//
//  FMDBManager.swift
//  HMWeiBo
//
//  Created by Apple on 16/8/10.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit
import FMDB

class FMDBManager{
    
    static let shareInstance: FMDBManager = FMDBManager()
    
    // 声明一个数据库句柄
    let queue: FMDatabaseQueue
    
    private init(){
        
        let path = (NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, .UserDomainMask, true).last! as NSString).stringByAppendingPathComponent("weibo.db")
        
        queue = FMDatabaseQueue(path: path)
        
        //创建表
        createTabel()
    }
    
    private func createTabel(){
        
        let sql = "CREATE TABLE IF NOT EXISTS 'T_Status' (" +
        "'status' text," +
        "'statusId' integer NOT NULL," +
        "'userId' integer," +
        "PRIMARY KEY('statusId')" +
        ");"
        
        print(sql)
        
        queue.inDatabase { (db) -> Void in
            if db.executeStatements(sql) {
                
                printLog("表格创建成功")
            }
        }
        
        
        
    }
    
}
